package org.sag.mallbf;

import java.io.DataOutputStream;
import java.util.HashMap;
import java.util.List;

/**
 * Custom Header Spec
 *
 * Int32 0
 * Int32 Multiplier
 * Int32 ObjId
 */
public class VGroup extends ObjGroup {

    public VGroup() {
        value = new HashMap<>();
        g = "";
    }

    @Override
    public void exportHeader(DataOutputStream dos, int version) throws Exception {
        Utils.putInt(dos, 0, 1);
        Utils.putFloat(dos, 0.0001f, 1);
        Utils.putInt(dos, 0, 1);
    }

    @Override
    public void exportContent(DataOutputStream dos) throws Exception {

        Utils.putInt(dos, value.keySet().size(), 1);

        //multiplier: 1/1000
        for (Integer key : value.keySet()) {
            List<double[]> v = value.get(key);

            Utils.putInt(dos, v.size(), 1);
            Utils.putInt(dos, key, 1);
            Utils.putShort(dos, (short) -4, 1);
            Utils.putShort(dos, (short) 0, 1);

            for (double[] list : v) {
                Utils.putInt(dos, (int) (list[0] * 1000000), 1);
                Utils.putInt(dos, (int) (list[1] * 1000000), 1);
                Utils.putInt(dos, (int) (list[2] * 1000000), 1);
            }
        }
    }
}
